package com.letv.whatslive.model.convert;

import com.letv.whatslive.model.Carousel_ImageSrc;
import com.letv.whatslive.model.Chips;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * Created by shenyue on 2016/7/5.
 */
public class ChipsConvert {
    public static DBObject castChipsToDBObject(Chips chips) {
        DBObject dbo = new BasicDBObject();
        if (chips.getId() != null) {
            dbo.put("_id", chips.getId());
        }
        dbo.put("picUrl", ObjUtils.toString(chips.getPicUrl(), ""));
        dbo.put("adUrl", ObjUtils.toString(chips.getAdUrl(), ""));
        dbo.put("createTime", ObjUtils.toLong(chips.getCreateTime(), 0l));
        dbo.put("updateTime", ObjUtils.toLong(chips.getUpdateTime(), 0l));
        dbo.put("type", ObjUtils.toInteger(chips.getType(), 0));
        dbo.put("busiId", ObjUtils.toString(chips.getBusiId(), ""));
        dbo.put("priority", ObjUtils.toLong(chips.getPriority(), 0l));
        dbo.put("tag", ObjUtils.toString(chips.getTag(), ""));
        return dbo;

    }

    public static Chips castDBObjectToChips(DBObject dbObject) {
        Chips chips = new Chips();
        if (dbObject != null) {
            chips.setId(ObjUtils.toLong(dbObject.get("_id")));
            chips.setPicUrl(ObjUtils.toString(dbObject.get("picUrl")));
            chips.setAdUrl(ObjUtils.toString(dbObject.get("adUrl")));
            chips.setCreateTime(ObjUtils.toLong(dbObject.get("createTime")));
            chips.setUpdateTime(ObjUtils.toLong(dbObject.get("updateTime")));
            chips.setType(ObjUtils.toInteger(dbObject.get("type"), 0));
            chips.setBusiId(ObjUtils.toString(dbObject.get("busiId")));
            chips.setPriority(ObjUtils.toLong(dbObject.get("priority")));
            chips.setTag(ObjUtils.toString(dbObject.get("tag")));
        }

        return chips;
    }
}
